package com.xqb.modules.controller.exam;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.ExaExamResults;
import com.xqb.modules.domain.vo.ExamResultQuestionsVo;
import com.xqb.modules.domain.vo.ExamResultVo;
import com.xqb.modules.service.IExaExamResultsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 考试或测验结果Controller
 *
 * @author ruoyi
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/exam/examResults")
public class ExaExamResultsController extends BaseController {
    @Autowired
    private IExaExamResultsService exaExamResultsService;

    /**
     * 查询考试或测验结果列表
     */
    @PreAuthorize("@ss.hasPermi('exam:examResults:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExaExamResults exaExamResults) {
        startPage();
        List<ExamResultVo> list = exaExamResultsService.getExaExamResultsList(exaExamResults);
        return getDataTable(list);
    }

    /**
     * 导出考试或测验结果列表
     */
    @PreAuthorize("@ss.hasPermi('exam:examResults:export')")
    @Log(title = "考试或测验结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExaExamResults exaExamResults) {
        List<ExaExamResults> list = exaExamResultsService.selectExaExamResultsList(exaExamResults);
        ExcelUtil<ExaExamResults> util = new ExcelUtil<ExaExamResults>(ExaExamResults.class);
        util.exportExcel(response, list, "考试或测验结果数据");
    }

    /**
     * 获取考试或测验结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:examResults:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(exaExamResultsService.selectExaExamResultsById(id));
    }

    /**
     * 新增考试或测验结果
     */
    @PreAuthorize("@ss.hasPermi('exam:examResults:add')")
    @Log(title = "考试或测验结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExaExamResults exaExamResults) {
        return toAjax(exaExamResultsService.insertExaExamResults(exaExamResults));
    }

    /**
     * 修改考试或测验结果
     */
    @PreAuthorize("@ss.hasPermi('exam:examResults:edit')")
    @Log(title = "考试或测验结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExaExamResults exaExamResults) {
        return toAjax(exaExamResultsService.updateExaExamResults(exaExamResults));
    }

    /**
     * 删除考试或测验结果
     */
    @PreAuthorize("@ss.hasPermi('exam:examResults:remove')")
    @Log(title = "考试或测验结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(exaExamResultsService.deleteExaExamResultsByIds(ids));
    }

    /**
     * 查询考试或测验题目及结果
     */
    @PreAuthorize("@ss.hasPermi('exam:examResults:list')")
    @GetMapping("/allList")
    public TableDataInfo allList(ExaExamResults exaExamResults) {
        startPage();
        List<ExamResultQuestionsVo> list = exaExamResultsService.getExamResultQuestionList(exaExamResults);
        return getDataTable(list);
    }
}
